package net.vmiranda.traindroid.activities.buses;

import java.util.ArrayList;
import java.util.List;

import net.vmiranda.traindroid.R;
import net.vmiranda.traindroid.activities.GenericActivity;
import net.vmiranda.traindroid.beans.buses.PasadaDeAutobus;
import net.vmiranda.traindroid.business.service.BusesService;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ListView;

public class BusesActivity extends GenericActivity {
	
	BusesService busesService;
	EditText editTextParada;
	
	public BusesActivity(){
		super();
		busesService = BusesService.getInstance();
		
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.buses);
		
		setListeners();
	}

	public void setListeners() {
		
		
		Button bCalcularRuta = (Button) findViewById(R.id.btnBuscarParada);
		bCalcularRuta.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Log.e("Clickingg", "buttonCalcularRuta clicked");
				editTextParada = (EditText) findViewById(R.id.editTextParadaOrigen);
				ListView gvAutobuses = (ListView)findViewById(R.id.listView1);
				List<PasadaDeAutobus> pasadas =  busesService.getInformacionParada(Integer.valueOf(editTextParada.getText().toString()));
				
				List<String> pasadasString = new ArrayList<String>();
				
				
					for(PasadaDeAutobus pasada : pasadas){
						System.out.println(pasada.getHora()+" "+pasada.getLinea()+" "+pasada.getParada());
						pasadasString.add(pasada.getHora().replace("Salida / Departure", "")+" "+pasada.getLinea()+" "+pasada.getParada());
					}
					gvAutobuses.setAdapter(new ArrayAdapter<String>(BusesActivity.this, android.R.layout.simple_list_item_1,pasadasString));	
				
//				RenfeScrapper rS = new RenfeScrapper();
//				List<HorarioRuta> horarios = rS.doHorariosPetition("20110910", "10",String.valueOf(codigoOrigen) , String.valueOf(codigoFin), "00", "23");
//				EditText editText = (EditText)findViewById(R.id.editTextResultadoRutas);
//				for(HorarioRuta horario : horarios){
//					editText.append(horario.getSalidaOrigen()+" "+horario.getLlegadaDestino()+"\n");
//	
//				}

			}
		});
	}

	
	

}
